﻿@using Abp.Authorization.Users
@using Abp.Configuration
@using Abp.Json
@using Abp.Zero.Configuration
@using MyCompanyName.AbpZeroTemplate.Authorization.Users
@using MyCompanyName.AbpZeroTemplate.Web.Areas.AppAreaName.Models.Common.Modals
@using MyCompanyName.AbpZeroTemplate.Web.Areas.AppAreaName.Models.Users
@model CreateOrEditUserModalViewModel

<script>
    window.passwordComplexitySetting = @Html.Raw(Model.PasswordComplexitySetting.ToJsonString(indented: true));
</script>
@Html.Partial("~/Areas/AppAreaName/Views/Common/Modals/_ModalHeader.cshtml", new ModalHeaderViewModel(Model.IsEditMode ? (L("EditUser") + ": " + Model.User.UserName) : L("CreateNewUser")))

<div class="modal-body">
    <ul class="nav nav-tabs  m-tabs-line" role="tablist">
        <li class="nav-item m-tabs__item">
            <a href="#UserInformationsTab" class="nav-link m-tabs__link active" data-toggle="tab" role="tab">
                @L("UserInformations")
            </a>
        </li>
        <li class="nav-item m-tabs__item">
            <a href="#RolesTab" data-toggle="tab" role="tab" class="nav-link m-tabs__link">
                @L("Roles") <b class="badge badge-primary"><span id="assigned-role-count">@Model.AssignedRoleCount</span></b>
            </a>
        </li>
        <li class="nav-item m-tabs__item">
            <a href="#OrganizationUnitsTab" data-toggle="tab" role="tab" class="nav-link m-tabs__link">
                @L("OrganizationUnits")
            </a>
        </li>
    </ul>
    <div class="tab-content">
        <div class="tab-pane active" id="UserInformationsTab" role="tabpanel">
            <form name="UserInformationsForm" role="form" novalidate class="form-validation">

                @if (Model.IsEditMode)
                {
                    <input type="hidden" name="Id" value="@Model.User.Id" />
                }

                <div class="row">
                    <div class="col-sm-3 text-center margin-top-15 margin-bottom-15">
                        @if (Model.ProfilePictureId.HasValue)
                        {
                            <img src="@Url.Action("GetProfilePictureById", "Profile", new { area = string.Empty })?id=@(Model.ProfilePictureId.Value)" width="128" height="128" class="img-thumbnail img-rounded user-edit-dialog-profile-image" />
                        }
                        else
                        {
                            <img src="@Url.Content("~/Common/Images/default-profile-picture.png")" width="128" height="128" class="img-thumbnail img-rounded user-edit-dialog-profile-image" />
                        }
                    </div>
                    <div class="col-sm-9">
                        <div class="form-group">
                            <label for="Name">@L("Name")</label>
                            <input id="Name" class="form-control" value="@Model.User.Name" type="text" name="Name" required maxlength="@MyCompanyName.AbpZeroTemplate.Authorization.Users.User.MaxNameLength">
                        </div>

                        <div class="form-group">
                            <label for="Surname">@L("Surname")</label>
                            <input id="Surname" type="text" name="Surname" class="form-control" value="@Model.User.Surname" required maxlength="@MyCompanyName.AbpZeroTemplate.Authorization.Users.User.MaxSurnameLength">
                        </div>
                    </div>
                </div>

                <div class="form-group">
                    <label for="EmailAddress">@L("EmailAddress")</label>
                    <input id="EmailAddress" type="email" name="EmailAddress" class="form-control" value="@Model.User.EmailAddress" required maxlength="@AbpUserBase.MaxEmailAddressLength">
                </div>

                <div class="form-group">
                    <label for="PhoneNumber">@L("PhoneNumber")</label>
                    <input id="PhoneNumber" type="text" name="PhoneNumber" class="form-control" value="@Model.User.PhoneNumber" maxlength="@UserConsts.MaxPhoneNumberLength">
                </div>

                <div class="form-group form-md-line-input form-md-floating-label">
                    <label for="UserName">@L("UserName")</label>
                    <input id="UserName" type="text" @Html.Raw(!Model.CanChangeUserName ? "disabled=\"disabled\"" : "") name="UserName" class="form-control" value="@Model.User.UserName" required maxlength="@AbpUserBase.MaxUserNameLength">
                    @if (!Model.CanChangeUserName)
                    {
                        <span class="help-block">@L("CanNotChangeAdminUserName")</span>
                    }
                </div>

                <div class="m-checkbox-list">
                    <label for="EditUser_SetRandomPassword" class="m-checkbox">
                        <input id="EditUser_SetRandomPassword" type="checkbox" name="SetRandomPassword" value="true" @Html.Raw(Model.IsEditMode ? "" : "checked=\"checked\"") />
                        @L("SetRandomPassword")
                        <span></span>
                    </label>
                </div>

                <div class="form-group user-password" style="@(Model.IsEditMode ? "display:block" : "display:none")">
                    <label for="EditUser_Password">@L("Password")</label>
                    <input id="EditUser_Password" type="password" name="Password" class="form-control" maxlength="@MyCompanyName.AbpZeroTemplate.Authorization.Users.User.MaxPlainPasswordLength" autocomplete="off" >
                </div>

                <div class="form-group user-password" style="@(Model.IsEditMode ? "display:block" : "display:none")">
                    <label for="PasswordRepeat">@L("PasswordRepeat")</label>
                    <input id="PasswordRepeat" type="password" name="PasswordRepeat" class="form-control" maxlength="@MyCompanyName.AbpZeroTemplate.Authorization.Users.User.MaxPlainPasswordLength" equalto="#EditUser_Password" autocomplete="off" >
                </div>

                <div class="m-checkbox-list">
                    <label for="EditUser_ShouldChangePasswordOnNextLogin" class="m-checkbox">
                        <input id="EditUser_ShouldChangePasswordOnNextLogin" type="checkbox" name="ShouldChangePasswordOnNextLogin" value="true" @Html.Raw(Model.User.ShouldChangePasswordOnNextLogin ? "checked=\"checked\"" : "")>
                        @L("ShouldChangePasswordOnNextLogin")
                        <span></span>
                    </label>
                    <label for="EditUser_SendActivationEmail" class="m-checkbox">
                        <input id="EditUser_SendActivationEmail" type="checkbox" name="SendActivationEmail" value="true" @Html.Raw(Model.IsEditMode ? "" : "checked=\"checked\"")>
                        @L("SendActivationEmail")
                        <span></span>
                    </label>
                    <label for="EditUser_IsActive" class="m-checkbox">
                        <input id="EditUser_IsActive" type="checkbox" name="IsActive" value="true" @Html.Raw(Model.User.IsActive ? "checked=\"checked\"" : "")>
                        @L("Active")
                        <span></span>
                    </label>
                    @if (SettingManager.GetSettingValue<bool>(AbpZeroSettingNames.UserManagement.TwoFactorLogin.IsEnabled))
                    {
                        <label for="EditUser_IsTwoFactorEnabled" class="m-checkbox">
                            <input id="EditUser_IsTwoFactorEnabled" type="checkbox" name="IsTwoFactorEnabled" value="true" @Html.Raw(Model.User.IsTwoFactorEnabled ? "checked=\"checked\"" : "")>
                            @L("IsTwoFactorEnabled")
                            <span></span>
                        </label>
                    }
                    @if (SettingManager.GetSettingValue<bool>(AbpZeroSettingNames.UserManagement.UserLockOut.IsEnabled))
                    {
                        <label for="EditUser_IsLockoutEnabled" data-toggle="tooltip" title="@L("IsLockoutEnabled_Hint")" class="m-checkbox">
                            <input id="EditUser_IsLockoutEnabled" type="checkbox" name="IsLockoutEnabled" value="true" @Html.Raw(Model.User.IsLockoutEnabled ? "checked=\"checked\"" : "")>
                            @L("IsLockoutEnabled")
                            <span></span>
                        </label>
                    }
                </div>

            </form>
        </div>
        <div class="tab-pane" id="RolesTab" role="tabpanel">
            <div class="user-role-checkbox-list">
                @foreach (var role in Model.Roles)
                {
                    <div class="m-checkbox-list">
                        <label for="EditUser_@(role.RoleName)" class="m-checkbox">
                            <input id="EditUser_@(role.RoleName)" type="checkbox" name="@(role.RoleName)" value="true" @Html.Raw(role.IsAssigned ? "checked=\"checked\"" : "")>
                            @role.RoleDisplayName
                            <span></span>
                        </label>
                    </div>
                }
            </div>
        </div>
        <div class="tab-pane" id="OrganizationUnitsTab" role="tabpanel">
            <div class="list-group">
                @Html.Partial("~/Areas/AppAreaName/Views/Common/_OrganizationTree.cshtml", Model)
            </div>
        </div>
    </div>
</div>

@Html.Partial("~/Areas/AppAreaName/Views/Common/Modals/_ModalFooterWithSaveAndCancel.cshtml")
